package com.lry.jvm.instructions.reserved;

import com.lry.jvm.instructions.base.NoOperandsInstruction;
import com.lry.jvm.jnative.NativeMethod;
import com.lry.jvm.jnative.Registry;
import com.lry.jvm.jnative.java.lang._Class;
import com.lry.jvm.jnative.java.lang._Object;
import com.lry.jvm.rtda.Frame;
import com.lry.jvm.rtda.heap.JMethod;
import com.lry.jvm.util.Util;

public class invokenative extends NoOperandsInstruction {
    @Override
    public byte getOpCode() {
        return (byte) 0xfe;
    }

    @Override
    public void execute(Frame frame) throws Exception {
        JMethod method = frame.getMethod();
        String className = method.getJClass().getName();
        String methodName = method.getName();
        String methodDescriptor = method.getDescriptor();

//        NativeMethod nativeMethod = Registry.findNativeMethod(className,methodName,methodDescriptor);
//        if (nativeMethod == null) {
//            String methodInfo = className + "." + methodName + methodDescriptor;
//            Util.panic("java.lang.UnsatisfiedLinkError: " + methodInfo);
//        }

        Registry.register(className,methodName,methodDescriptor,new NativeMethod(frame));
        _Object.init(frame);
        _Class.init(frame);
    }
}
